
# -*- coding: utf-8 -*- 
from am import AndroidAm
from logcat import logcat
import os,sys
import string

"""关于设备的一些操作"""

class StaDev():
	WIFI_ENABLE = 0
	IP="127.0.0.1"
	_id=''
	_dev_name=''
	_playurl=''
	_logcatprocess=''
	_stepfile=''
	_ssid=''
	_password=''
	_priority=''
	_am=AndroidAm()
	_logcat=logcat()
	def __init__(self,id,playurl,ssid,password,ping_address,http_url):
		self._id=id
		self._playurl=playurl
		self._ssid=ssid
		self._password=password
		self._ping_address = ping_address
		self._http_url = http_url
	def GetHttpAddress(self):
		return self._http_url
	def GetPingAddress(self):
		return self._ping_address
	"""获取无线SSID"""
	def GetWifiSsid(self):
		return self._ssid
	"""获取无线密码"""
	def GetWifiPassword(self):
		return self._password
	"""获取设备ID"""
	def GetId(self):
		return self._id
	"""获取设备播放地址"""
	def GetPlayUrl(self):
		return self._playurl
	"""获取设备日志输出进程号"""
	def GetLogCatProcess(self):
		return self._logcatprocess
	"""打开设备默认浏览器"""
	def OpenBrowser(self):
		print 'open brower ' + self._id + '\n'
		self._am.startBrowser(self._playurl,self._id)
	"""连接无线SSID password=null 为不加密"""
	def ConnectWifi(self):
		print 'Connect '+  self._ssid + ":" + self._password + "-" + self._id + '\n'
		self._am.ConnectWifi(self._id,self._ssid,self._password)
	"""断开无线连接"""
	def DisconnectWifi(self):
		print 'Disconnect wifi' + self._id + '\n'
		self._am.disConnectWifi(self._id)
	"""关闭设备默认浏览器"""
	def StopBrowser(self):
		print 'stop brower ' + self._id + '\n'
		self._am.stopBrowser(self._id)
	"""打开设备播放器"""
	def OpenPlayer(self):
		print 'open Player ' + self._id + '\n'
		self._am.startPlayer(self._playurl,self._id)
	"""关闭设备播放器"""
	def StopPlayer(self):
		print 'stop Player ' + self._id + '\n'
		self._am.stopPlayer(self._id)
	"""打开无线数据收集"""
	def OpenWifiData(self):
		print 'open Wifi data ' + self._id + '\n'
		self._am.startWifiData(self._id,self._ping_address,self._http_url)

	def OpenHttpGet(self):
		print 'open http get ' + self._id + '\n'
		self._am.startHttpGet(self._id,self._http_url)

	def OpenPing(self):
		print 'open ping ' + self._id + '\n'
		self._am.startPing(self._id,self._ping_address)
		
	"""关闭无线数据收集"""
	def StopWifiData(self):
		print 'stop Wifi data ' + self._id + '\n'
		self._am.stopWifiData(self._id)
	"""根据步奏操作设备网页"""
	def StartPlay(self):
		print 'start play ' + self._id + '\n'
		os.popen("monkeyrunner "+str(os.getcwd())+"\\startplay.py " + self._id + ' ' + self._stepfile)
	"""打开设备日志输出"""
	def OpenLogCat(self):
		print 'open log cat ' + self._id + '\n'
		self._logcatprocess=self._logcat.start(self._id)
	"""关闭设备日志输出"""
	def StopLogCat(self):
		print 'stop log cat ' + self._id + '\n'
		self._logcat.stop(self._logcatprocess.pid)
	"""开启endpoint"""
	def StartEndpoint(self):
		print 'start endpoint' + self._id + '\n'
		self._am.startEndpoint(self._id)
	def StopEndpoint(self):
		print 'stop endpoint' + self._id + '\n'
		self._am.stopEndpoint(self._id)	
	def getIpAddr(self):
		ip = self._am.getIpAddr(self._id)
		return ip
	def getGwAddr(self,gw):
		return self._am.getGwAddr(self._id,gw)
	